﻿using System;
using System.Collections.Generic;
using System.Text;
using privacyUtils;

namespace bookMaster.AssetSystem.Shell.Clases
{
    public class LogInfo
    {
        ECodeEngine edCode = new ECodeEngine();

        public void ConnectionParameters()
        {
            bookMaster.AssetSystem.Data.SqlClient.SqlNetTiersProvider provider = new bookMaster.AssetSystem.Data.SqlClient.SqlNetTiersProvider();
            System.Collections.Specialized.NameValueCollection collection = new System.Collections.Specialized.NameValueCollection();
            collection.Add("ConnectionString", GetConnectionString(Properties.Settings.Default.Server, Properties.Settings.Default.Database, Properties.Settings.Default.SecureUser, Properties.Settings.Default.SecurePassword));
            collection.Add("ConnectionStringName", "BookMasterConnection");
            collection.Add("UseStoredProcedure", "true");
            collection.Add("EnableEntityTracking", "false");
            collection.Add("EntityCreationalFactoryType", "bookMaster.AssetSystem.mTier.Entities.EntityFactory");
            collection.Add("EnableMethodAuthorization", "false");
            collection.Add("ProviderInvariantName", "System.Data.SqlClient");
            provider.Initialize("BookMasterConnection", collection);

            bookMaster.AssetSystem.Data.DataRepository.LoadProvider(provider, true);
        }

        private string GetConnectionString(string server, string db, string secureUsr, string securePass)
        {
            return "Data Source=" + server + ";Initial Catalog=" + db + ";User Id=" + edCode.desencriptar(secureUsr) + "; Password=" + edCode.desencriptar(securePass) + ";"; 
        }

        public static string GetFingerprint(string user, string pass)
        {
            return HashValues.CalculateHash(pass.Trim() + user.Trim().ToUpper(), System.Text.Encoding.UTF32, "SHA256");
        }

        public static string GetCurrentUserName()
        {
            ECodeEngine dCode = new ECodeEngine();
            string secureUser = dCode.desencriptar(Properties.Settings.Default.SecureUser);
            return secureUser;
        }

        public static string GetCurrentPass()
        {
            ECodeEngine dCode = new ECodeEngine();
            string securePassword = dCode.desencriptar(Properties.Settings.Default.SecurePassword);
            return securePassword;
        }

        public static string GetServerName()
        {
            return Properties.Settings.Default.Server.ToString();
        }

        public static string GetDataBaseName()
        {
            return Properties.Settings.Default.Database.ToString();
        }
    }
}
